package com.sht.product.yuea.weixin.request;

import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.message.BasicHeader;
import org.apache.http.protocol.HTTP;

import com.alibaba.fastjson.JSONObject;
import com.sht.common.components.httpClient.DefaultCloseableHttpClient;

public class TemplateMessageSender {
	private static final String APPLICATION_JSON = "application/json";  
    private static final String CONTENT_TYPE_TEXT_JSON = "text/json";  
	private static String url="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=";
	public static Response SendFailedException(JSONObject msg) throws SendErrorException {
		String tocken=TockenGetter.getTocken();
		HttpPost httpPost=new HttpPost(url+tocken);
        httpPost.addHeader(HTTP.CONTENT_TYPE, APPLICATION_JSON);  
        StringEntity se=new StringEntity(msg.toJSONString(),ContentType.APPLICATION_JSON);
        se.setContentType(CONTENT_TYPE_TEXT_JSON);  
        se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, APPLICATION_JSON));  
        httpPost.setEntity(se);  
        String resultStr = new DefaultCloseableHttpClient().executePost(httpPost);
		JSONObject result = JSONObject.parseObject(resultStr);
		return new Response(result);
	}
}
